//
//  SecondViewController.m
//  真·豆瓣半完全体
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "SecondViewController.h"
#import "MyTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "SecondViewController2.h"
#import "SecondViewController3.h"
@interface SecondViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arrData;

@property (nonatomic, retain) NSMutableDictionary *nameDic2;
@end

@implementation SecondViewController
- (void)dealloc{
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:84/255.0 green:139/255.0 blue:156/255.0 alpha:1];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"电影";
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_nav_collection@2x.png"] style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
    item.tintColor = [UIColor blackColor];
    self.navigationItem.rightBarButtonItem = item;

    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 375, 554) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView release];
    
    [self dataHandle];
    [_tableView registerClass:[MyTableViewCell class] forCellReuseIdentifier:@"cell"];
    self.nameDic2 = [NSMutableDictionary dictionary];
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _arrData.count;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.imgView.image = [UIImage imageNamed:@"bg_eventlistcell@2x.png"];
//    cell.imgView1.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.jpg", indexPath.row + 1]];
    cell.myLabel.text =  [NSString stringWithFormat:@"片名：%@",[_arrData[indexPath.row] objectForKey:@"title"]];
    cell.myLabel.textAlignment = NSTextAlignmentCenter;
    
    
    NSDictionary *dic = _arrData[indexPath.row][@"images"];
    [cell.imgView1 sd_setImageWithURL:[NSURL URLWithString:dic[@"large"]]];
    
    return cell;
}

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SecondViewController3 *sVc3 = [[SecondViewController3 alloc] init];
    sVc3.rating = _arrData[indexPath.row][@"rating"];
    NSMutableDictionary *dic  =  _arrData[indexPath.row][@"images"];
    sVc3.img = dic[@"large"];
    sVc3.title1 = _arrData[indexPath.row][@"title"];
    
    sVc3.block = ^(NSString *str){
        [_nameDic2 setObject:@"已收藏" forKey:str];
    };
    
    sVc3.nameDic3 = _nameDic2;
    [self.navigationController pushViewController:sVc3 animated:YES];
}




- (void)itemAction:(UIBarButtonItem *)item{
    SecondViewController2 *sVc2 = [[SecondViewController2 alloc] init];
    sVc2.arrData2 = _arrData;
    [self.navigationController pushViewController:sVc2 animated:YES];
    
}


- (void) dataHandle{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"plist"];
    self.arrData = [NSMutableArray arrayWithContentsOfFile:path];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
